<?php if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * @description COURSE MODEL
 */
class courses_model extends Model {

    /**
     * @desc Constructor
     */
    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    /**
     * @desc Insert Course
     * @param <array> $arrData
     * @return <bool> true else failed or NULL
     */
    public function insert($arrData) {
        $arrDefault = array(
            COURSES_PROVIDER_ID => NULL,
            COURSES_COURSE_NAME => NULL,
            COURSES_COURSE_DESCRIPTION => NULL,
            COURSES_CREATE_DATE => NULL,
            COURSES_START_DATE => NULL,
            COURSES_END_DATE => NULL,
            COURSES_MAX_NUM_LEARNER => NULL,
            COURSES_ADDRESS => NULL,
            COURSES_MAX_DAY_REGISTER_OFFLINE => NULL,
            COURSES_ORIGINAL_FEE => NULL,
            COURSES_DISCOUNT_FEE => NULL,
            COURSES_ENTRY_REQUIREMENT => NULL,
            COURSES_REGISTRATION_APPROVE => NULL,
            COURSES_OTHER_INFO => NULL,
        );

        $arrInput = array_merge($arrDefault, $arrData);
        try {
            $this->db->insert('courses', $arrInput);
        }
        catch (Exception $e) {
            print_r($e);
        }
        return true;
    }

    //End insert Course
    function getCourseById($arrData) {
        try {
            $cond = array(
                COURSES_PROVIDER_ID => $arrData['userid'],
                COURSES_COURSE_ID => $arrData['course_id']
                );
            $this->db->where($cond);
            $result = $this->db->get('courses')->row();
        }
        catch (Exception $e) {
            print_r($e);
        }
        return $result;
    }
}

?>